package pers.lance.xml.parse;

import pers.lance.xml.db.bean.Student;

import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import java.io.File;
import java.util.List;

public class XmlParse {
    public List<Student> parseStudent(String path) {
        StudentHandler studentHandler = new StudentHandler();

        //创建解析工厂
        SAXParserFactory factory = SAXParserFactory.newInstance();
        //得到SAX的解析器
        try {
            SAXParser parser = factory.newSAXParser();
            parser.parse(new File(path), studentHandler);
            return studentHandler.getStudents();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return null;
    }
}
